package com.didispace.hystrix;

import com.didispace.web.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class DefineServiceDegradationController {

    @Autowired
    UserService userService;

    // p155  定义服务降级
    @RequestMapping(value = "/defineServiceDegradation/{id}", method = RequestMethod.GET)
    @ResponseBody
    private User defineServiceDegradation(@PathVariable Long id) {
        return userService.getUserById(id);
    }

    // p157  异常处理 -- 异常传播
    @RequestMapping(value = "/InterruptedEException/{id}", method = RequestMethod.GET)
    @ResponseBody
    private User InterruptedEException(@PathVariable Long id) {
        return userService.getUserById2(id);
    }

    // p157  异常处理 -- 异常获取
    @RequestMapping(value = "/CapturedEException/{id}", method = RequestMethod.GET)
    @ResponseBody
    private User CapturedEException(@PathVariable String id) {
        return userService.getUserById3(id);
    }
}

// http://localhost:9000/defineServiceDegradation/1
// {
//     "id": 1,
//     "name": null,
//     "age": null
// }
// http://localhost:9000/defineServiceDegradation/2
// {
//     "id": 2,
//     "name": null,
//     "age": null
// }